// message.c
#define SZ 75

varargs string wrap(string str, int width) {
	if (!width) return sprintf("%-=*s\n", SZ, str);
	else return sprintf("%-=*s\n", width, str);
}

varargs void message_vision(string msg, object me, object you)
{
	string my_gender, your_gender, my_name, your_name;
	string str1, str2, str3;

	my_name= (string)me->name();
	my_gender = (string)me->query("gender");
	str1 = replace_string(msg,  "$P", gender_self(my_gender));
	str1 = replace_string(str1, "$N", gender_self(my_gender));
	str3 = replace_string(msg,  "$P", my_name);
	str3 = replace_string(str3, "$N", my_name);
	if( you ) {
		your_name= you->name();
		your_gender= you->query("gender");
		str2 = replace_string(msg,  "$P", gender_pronoun(my_gender));
		str2 = replace_string(str2, "$p", gender_self(your_gender));
		str2 = replace_string(str2, "$N", my_name);
		str2 = replace_string(str2, "$n", gender_self(your_gender));
		message("vision", str2, you);
		str1 = replace_string(str1, "$p", gender_pronoun(your_gender));
		str1 = replace_string(str1, "$n", your_name);
		str3 = replace_string(str3, "$p", your_name);
		str3 = replace_string(str3, "$n", your_name);
	}
	message("vision", str1, me);
//	message("vision", str3,  environment(me), ({ me, you}) );
   if(environment(me)) {
       if(you)
         message("vision", str3,  environment(me), ({ me, you}) );
     else
         message("vision", str3,  environment(me), ({ me}));
       if(environment(me)->query("info_sends"))
          environment(me)->info_sends(str3);
   }
}

void tell_object(object ob, string str)
{
	message("tell_object", str, ob);
}

varargs void tell_room(mixed ob, string str, object *exclude)
{
//	if( ob ) message("tell_room", str, ob, exclude);
	if (ob) {
		message("tell_room", str, ob, exclude);
		if(ob->query("info_sends"))
			ob->info_sends(str);
	}
}

void shout(string str)
{
	message("shout", str, users(), this_player());
}

void write(string str)
{
	if( this_player() )
		message("write", str, this_player());
	else if( previous_object() )
		message("write", str, previous_object());
	else
		efun::write(str);
}

varargs void say(string str, mixed exclude)
{
	if( living(previous_object()) )
		message("say", str, environment(previous_object()), previous_object());
	else if( this_player() )
		message("say", str, environment(this_player()), this_player());
       if(environment(this_player())->query("info_sends"))
          environment(this_player())->info_sends(str);
}

int notify_fail(string error)
{
	if( this_player() ) {
		if(this_player()->query_temp("gb_player")) error=LANGUAGE_D->Big52GB(error);
		return efun::notify_fail(error);
	} else if( previous_object() ) {
		return efun::notify_fail(error);
	} else
		return efun::notify_fail(error);
	
}

